package com.vhans.aapi.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.core.web.page.TableDataInfo;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.request.RequestDTO;
import com.vhans.db.model.vo.request.RequestInfoVO;
import com.vhans.db.model.vo.request.RequestVO;
import com.vhans.db.service.ICRequestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 好友请求Controller控制器
 *
 * @author vhans
 * @date 2023-05-21
 */
@Api(tags = "好友请求模块")
@RestController
@RequestMapping("Integer/request")
public class RequestController extends BaseController {
    @Autowired
    private ICRequestService cRequestService;

    /**
     * 查询好友请求列表
     *
     * @param condition 条件
     * @return {@link RequestVO} 题目列表
     */
    @ApiOperation(value = "查询好友请求列表")
    @SaCheckPermission("chat:request:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<RequestVO> list = cRequestService.selectRequestVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取好友请求详细信息
     *
     * @param id 好友请求id
     * @return {@link Result<RequestInfoVO>} 好友请求信息
     */
    @ApiOperation(value = "获取好友请求编辑信息")
    @SaCheckPermission("chat:request:query")
    @GetMapping(value = "/info/{id}")
    public Result<RequestInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(cRequestService.selectRequestInfoById(id));
    }

    /**
     * 删除好友请求
     *
     * @param idList 需要删除的好友请求主键列表
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除好友请求")
    @SaCheckPermission("chat:request:delete")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> idList) {
        return toAjax(cRequestService.deleteRequestByIdIdList(idList));
    }
}
